<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>代码跳转</title>
    <script src="https://cdn.jsdelivr.net/npm/vue"></script>
    <script src="https://unpkg.com/vue-router/dist/vue-router.js"></script>

    <style>
        .circle{
            width: 100px;
            height: 100px;
            border-radius: 50%;
            line-height: 100px;
            text-align: center;
        }
        .nima{
            background-color: green;
        }
        .hehe{
            background-color: chocolate;
        }
        .wangba{
            background-color: cornflowerblue;
        }
        .link{
            font-size: 20px;
        }
        .link a{
            color: dodgerblue;
        }
        .jumpBlock{
            font-size: 0;
        }
        .jumpBlock>div{
            font-size: 20px;
            display: inline-block;

        }
    </style>
</head>

<body>
<div id="app">
    <h1>路由导航</h1>
    <div class="link">更多参考：<a href="https://router.vuejs.org/zh-cn/essentials/navigation.html">https://router.vuejs.org/zh-cn/essentials/navigation.html</a></div>
    <p></p>

    <div class="jumpBlock">


    <!--这是路由入口，点击跳转-->
    <div @click="jumpTo" :class="nima.class" >{{nima.text}}</div>
    <div @click="jumpTo" :class="hehe.class">{{hehe.text}}</div>
    <div @click="jumpTo" class="circle wangba">王八</div>
    <!--路由出口。内容渲染在此-->
    </div>
        <router-view ></router-view>
</div>

<script>
    // 1定义路由组件对象。实际上可以拆分到另一个文件中，通过import导入
    var nimaR = {template:"<div class='nima'>尼玛达</div>"};
    var heheR = {template:"<div class='hehe'>呵呵哒</div>"};

    // 2导入路由对象。定义路由列表
    var routes = [
        {path:"/nima",component:nimaR},
        {path:"/hehe",component:heheR},
    ];

    //3 创建Vue路由实例
    var vueRouter = new VueRouter({routes:routes});

    //4 挂载路由
    var v = new Vue({
        router:vueRouter,
        data:{
          nima:{class:"circle nima",text:"尼玛"},
          hehe:{class:"circle hehe",text:"呵呵"},
        },
        methods:{
            jumpTo:function (e) {
                var css = e.target.classList;
                if (css.contains("nima")){
                    this.$router.push("/nima");
                }else if (css.contains("hehe")) {
                    this.$router.push("/hehe");
                }else{
                    this.$router.push({path:"nima"});
                }
                console.log(this.$router)
            }
        }
    }).$mount("#app");


</script>

</body>
</html>